package cn.school.thoughtworks.section2;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class PracticeA {
    Map<String,Integer> countSameElements(List<String> collection1) {
        //实现练习要求，并改写该行代码。
        Map<String, Integer> nameMap = new HashMap();
        collection1.forEach(name -> nameMap.compute(name, (k, v) -> v == null ? 1 : ++v));
        return nameMap;


      /*  Map map=new HashMap();
        Object[] objects = collection1.toArray();
        for(int i=0;i<objects.length;i++){
            if(map.get(objects[i])!=null){
                Integer integer= (Integer) map.get(objects[i]);
                integer++;
                map.put(objects[i],integer);
            }else {
                map.put(objects[i], 1);
            }
        }
        return map;*/
    }
}
